/*
ConstructData.do
"Human Capital and Climate Change", 
	by Noam Angrist, Kevin Winseck, Harry Patrinos, and Joshua Graff Zivin.
	
Constructs data for all rounds of ESS by merging survey rounds together 
	and then constructing relevant variables.

Inputs:
	minEduPanel.dta *This is a cleaned version of the WB spreadsheet, created by "1_ParseCSLs.do"
	ESS9e03_1.dta *These are the raw ESS files downloaded from ESS
	ESS8e02_2.dta
	ESS7e02_2.dta
	ESS6e02_4.dta
	ESS5e03_4.dta
	ESS4e04_5.dta
	ESS3e03_7.dta
	ESS2e03_6.dta
	ESS1e06_6.dta
Outputs:
	Cleaned_ESS.dta


*/




********************************************************************************
*** Import data
********************************************************************************

* Outcomes to keep during the append. Otherwise we end up with too many variables for Stata to handle (because different ESS rounds have some different questions)
local outcomeslist "impenv elgcoal wrdpfos clmchng wrclmch ccgdbd inctxff sbsrnen banhhap lrscale eneffap rdcenr clmthgt1 clmthgt2"
local additionaloutcomes "hinctnta polintr vote prtv* contplt wrkprty prtcl* gincdif freehms euftf imsmetn imdfetn imbgeco imwbcnt elgngas elghydr elgnuc elgsun elgwind elgbio wrpwrct wrenexp"

use "ESS9e03_1.dta", clear

append using "ESS8e02_2.dta"  
append using "ESS7e02_2.dta"
append using "ESS6e02_4.dta"
append using "ESS5e03_4.dta"
append using "ESS4e04_5.dta"
append using "ESS3e03_7.dta"
keep agea yrbrn eduyrs essround cntry region gndr brncntr cntbrthd `outcomeslist' `additionaloutcomes' /*Prevents the append from having too many unnecessary columns*/
append using "ESS2e03_6.dta"
append using "ESS1e06_6.dta"
keep agea yrbrn eduyrs essround cntry region gndr brncntr cntbrthd `outcomeslist' `additionaloutcomes'






* Merge in reform data to get CSLs *****************************************************
 
merge n:1 yrbrn cntry using "minEduPanel.dta" 
 
keep if _merge==3 /*keep only countries we have reforms for, and reforms we have countries for. Drop individuals who didn't merge because their birthyear was missing*/




*** Make selections and clean data
gen in_sample = agea>25 & !mi(agea) & !mi(eduyrs) & eduyrs>0


********************************************************************************
*** Construct Outcomes *********************************************************
********************************************************************************

* Program to create an above median indicator given a variable name
cap program drop aboveMedian
program aboveMedian
	args var
	qui su `var'_recoded, det
	gen `var'_proenv = `var'_recoded>= `r(p50)' if !mi(`var'_recoded)
	local lab: variable label `var'_recoded
	label var `var'_proenv "`lab'"
end


/*
	impenv
		Now I will briefly describe some people. Please listen to each description and
		tell me how much each person is or is not like you. Use this card for your
		answer. She/he strongly believes that people should care for nature. Looking
		after the environment is important to her/him.
			1 Very much like me
			2 Like me
			3 Somewhat like me
			4 A little like me
			5 Not like me
			6 Not like me at all*/

gen impenv_recoded = (6 - impenv) / 5
label var impenv_recoded "Importance to care for nature and environment"
aboveMedian "impenv"
		
/*		
ESS 2016 Only:
	eneffap
		If you were to buy a large electrical appliance for your home, how likely is it
		that you would buy one of the most energy efficient ones?
			0 Not at all likely - 10 Extremely likely
*/

gen eneffap_recoded = eneffap / 10
label var eneffap_recoded  "How likely to buy most energy efficient home appliance"
aboveMedian "eneffap"

/*
	rdcenr
		There are some things that can be done to reduce energy use, such as
		switching off appliances that are not being used, walking for short journeys,
		or only using the heating or air conditioning when really needed. In your daily
		life, how often do you do things to reduce your energy use?
			1 Never
			2 Hardly ever
			3 Sometimes
			4 Often
			5 Very often
			6 Always
			55 Cannot reduce energy use
			*/
gen rdcenr_recoded = (rdcenr - 1) /5 if rdcenr!=55
label var rdcenr_recoded "How often do things to reduce energy use"
aboveMedian "rdcenr"	
/*			
	elgcoal
		The highlighted box at the top of this card shows a number of energy sources
		that can be used to generate electricity. Please take a moment to look over
		them. How much of the electricity used in [country] should be generated
		from each energy source? First, how much of the electricity used in [country]
		should be generated from coal?
			1 A very large amount
			2 A large amount
			3 A medium amount
			4 A small amount
			5 None at all
			55 I have not heard of this energy source before
			*/

gen elgcoal_recoded = (elgcoal-1)/4 if elgcoal!=55	
label var elgcoal_recoded "How much electricity should be generated from coal"	
aboveMedian "elgcoal"
		
		
/*		
Same coding as coal:

	elgngas
		Natural gas
	
	elghydr
		Hydroelectric
	
	elgnuc
		Nuclear power
		
	elgsun
		Solar
		
	elgwind
		Wind
		
	elgbio
		Biomass
		
Nuclear and gas are ambiguous so I define pro-evironmental as favoring non-fossil fuels (renewables plus nuclear). These are not used in the paper because of their ambiguity.
*/

gen elgngas_recoded = (elgngas-1)/4 if elgngas!=55	
label var elgngas_recoded "How much electricity should be generated from natural gas"	
aboveMedian "elgngas"

gen elghydr_recoded = (5-elghydr)/4 if elghydr!=55	
label var elghydr_recoded "How much electricity should be generated from hydro"	
aboveMedian "elghydr"

gen elgnuc_recoded = (5-elgnuc)/4 if elgnuc!=55	
label var elgnuc_recoded "How much electricity should be generated from nuclear"	
aboveMedian "elgnuc"


gen elgsun_recoded = (5-elgsun)/4 if elgsun!=55	
label var elgsun_recoded "How much electricity should be generated from solar"	
aboveMedian "elgsun"


gen elgwind_recoded = (5-elgwind)/4 if elgwind!=55	
label var elgwind_recoded "How much electricity should be generated from wind"	
aboveMedian "elgwind"	


gen elgbio_recoded = (5-elgbio)/4 if elgbio!=55	
label var elgbio_recoded  "How much electricity should be generated from biomass"	
aboveMedian "elgbio"		
				
/*
How worried are you that there may be power cuts in [country]?
1 Not at all worried
2 Not very worried
3 Somewhat worried
4 Very worried
5 Extremely worried
*/
		

gen wrpwrct_recoded = (5-wrpwrct)/4 if !mi(wrpwrct)
local wrpwrct_label label var wrpwrct_recoded
aboveMedian "wrpwrct"
				
/*
How worried are you that energy may be too expensive for many people in
[country]?
1 Not at all worried
2 Not very worried
3 Somewhat worried
4 Very worried
5 Extremely worried
*/	


gen wrenexp_recoded = (5-wrenexp)/4 if !mi(wrenexp)
label var wrenexp_recoded "How worried energy too expensive"	
aboveMedian "wrenexp"
		
/*		
	wrdpfos
		How worried are you about [country] being too dependent on using energy
		generated by fossil fuels such as oil, gas and coal?	
			1 Not at all worried
			2 Not very worried
			3 Somewhat worried
			4 Very worried
			5 Extremely worried
			*/

gen wrdpfos_recoded = (wrdpfos-1)/4
label var wrdpfos_recoded "How worried too dependent on fossil fuels"			
aboveMedian "wrdpfos"
			
			
/*			
	clmchng
		You may have heard the idea that the world's climate is changing due to
		increases in temperature over the past 100 years. What is your personal
		opinion on this? Do you think the world's climate is changing?
			1 Definitely changing
			2 Probably changing
			3 Probably not changing
			4 Definitely not changing
*/

gen clmchng_recoded = (4-clmchng)/3
label var clmchng_recoded "Do you think the world's climate is changing"
aboveMedian "clmchng"
			
/*			
	There are two clmthgt questions,
	clmthgt1 + clmthgt2 Depends on how they answered to belief about climate changing.
	Make one consolidated response (since respondents answered one or the other)
		How much have you thought about climate change before today?
			1 Not at all
			2 Very little
			3 Some
			4 A lot
			5 A great deal
*/

gen clmthgt_consolidated= .
forval i=1/5{
	replace clmthgt_consolidated = `i' if clmthgt1==`i' | clmthgt2==`i'
}
gen clmthgt_recoded = (clmthgt_consolidated-1)/4
label var clmthgt_recoded "How much thought about climate change before today"
aboveMedian "clmthgt"
	
/*	
	wrclmch
		How worried are you about climate change?
			1 Not at all worried
			2 Not very worried
			3 Somewhat worried
			4 Very worried
			5 Extremely worried
			*/

gen wrclmch_recoded = (wrclmch-1)/4
label var wrclmch_recoded  "How worried about climate change"	
aboveMedian "wrclmch"	
/*			
	ccgdbd
		How good or bad do you think the impact of climate change will be on people
		across the world? Please choose a number from 0 to 10, where 0 is extremely
		bad and 10 is extremely good.
			0 Extremely bad - 10 Extremely good
			*/

gen ccgdbd_recoded = (10-ccgdbd)/10	
label var ccgdbd_recoded "Climate change good or bad impact across world"	
aboveMedian "ccgdbd"
			
			
/*			
			
	inctxff
		To what extent are you in favour or against the following policies in [country]
		to reduce climate change? Increasing taxes on fossil fuels, such as oil, gas and
		coal.
			1 Strongly in favour
			2 Somewhat in favour
			3 Neither in favour nor against
			4 Somewhat against
			5 Strongly against
*/

gen inctxff_recoded = (5-inctxff)/4
label var inctxff_recoded "Favor increase taxes on fossil fuels to reduce climate change"
aboveMedian "inctxff"
			
/*			
	sbsrnen
		To what extent are you in favour or against the following policies in [country]
		to reduce climate change? Using public money to subsidise renewable energy
		such as wind and solar power.
			1 Strongly in favour
			2 Somewhat in favour
			3 Neither in favour nor against
			4 Somewhat against
			5 Strongly against
			
			*/

gen sbsrnen_recoded = (5-sbsrnen)/4
label var sbsrnen_recoded "Favor subsidise renewable energy to reduce climate change"
aboveMedian "sbsrnen"

			
/*			
	banhhap
		To what extent are you in favour or against the following policies in [country]
		to reduce climate change? A law banning the sale of the least energy efficient
		household appliances.
			1 Strongly in favour
			2 Somewhat in favour
			3 Neither in favour nor against
			4 Somewhat against
			5 Strongly against
*/
gen banhhap_recoded = (5-banhhap)/4
label var banhhap_recoded "Favor ban sale of energy inefficient household appliances to reduce cc"
aboveMedian "banhhap"




* Political outcomes ***********************************************************


/*
In politics people sometimes talk of "left" and "right". Using this card, where
would you place yourself on this scale, where 0 means the left and 10 means
the right?
*/

gen lrscale_recoded = (10-lrscale)/10
label var lrscale_recoded "Placement on left right scale"
aboveMedian "lrscale"



gen hinctnta_recoded = (hinctnta-1)/9
label var hinctnta_recoded "Household income decile"
aboveMedian hinctnta




********************************************************************************
*** Party preferences
********************************************************************************

gen has_party = !mi(prtvtcat) | !mi(prtvtdbe) | !mi(prtvtdbg) | !mi(prtvtgch) | !mi(prtvtbcy) | !mi(prtvtecz) | !mi(prtvtddk) | !mi(prtvtgee) | !mi(prtvtees) | !mi(prtvtdfi) | !mi(prtvtdfr) | !mi(prtvtcgb) | !mi(prtvtahr) | !mi(prtvtfhu) | !mi(prtvtcie) | !mi(prtvtcis) | !mi(prtvtcit) | !mi(prtvtalv) | !mi(prtvtme) | !mi(prtvtgnl) | !mi(prtvtbno) | !mi(prtvtdpl) | !mi(prtvtcpt) | !mi(prtvtrs) | !mi(prtvtcse) | !mi(prtvtfsi) | !mi(prtvtdsk) | !mi(prtvtbat) | !mi(prtvtcbe) | !mi(prtvtfch) | !mi(prtvtdcz) | !mi(prtvtfee) | !mi(prtvtdes) | !mi(prtvtcfr) | !mi(prtvtbgb) | !mi(prtvtehu) | !mi(prtvtbie) | !mi(prtvtcil) | !mi(prtvtbis) | !mi(prtvtbit) | !mi(prtvtfnl) | !mi(prtvtdru) | !mi(prtvtbse) | !mi(prtvtesi) | !mi(prtvtech) | !mi(prtvtcdk) | !mi(prtvteee) | !mi(prtvtces) | !mi(prtvtcfi) | !mi(prtvtaie) | !mi(prtvtcpl) | !mi(prtvtbpt) | !mi(prtvtal) | !mi(prtvtcbg) | !mi(prtvtdch) | !mi(prtvtacy) | !mi(prtvtccz) | !mi(prtvtdee) | !mi(prtvtgb) | !mi(prtvtdhu) | !mi(prtvtbil) | !mi(prtvtais) | !mi(prtvtenl) | !mi(prtvtano) | !mi(prtvtcru) | !mi(prtvtdsi) | !mi(prtvtcsk) | !mi(prtvtcua) | !mi(prtvtxk) | !mi(prtvtbbg) | !mi(prtvtcch) | !mi(prtvthr) | !mi(prtvtcy) | !mi(prtvtbcz) | !mi(prtvtbdk) | !mi(prtvtcee) | !mi(prtvtbes) | !mi(prtvtbfi) | !mi(prtvtbfr) | !mi(prtvtcgr) | !mi(prtvtchu) | !mi(prtvtdnl) | !mi(prtvtbpl) | !mi(prtvtbru) | !mi(prtvtase) | !mi(prtvtcsi) | !mi(prtvtbsk) | !mi(prtvtbua) | !mi(prtvtaat) | !mi(prtvtbbe) | !mi(prtvtabg) | !mi(prtvtbch) | !mi(prtvtacz) | !mi(prtvtbee) | !mi(prtvtafi) | !mi(prtvtbgr) | !mi(prtvtbhu) | !mi(prtvtie) | !mi(prtvtail) | !mi(prtvtlv) | !mi(prtvtcnl) | !mi(prtvtno) | !mi(prtvtapt) | !mi(prtvtaro) | !mi(prtvtaru) | !mi(prtvtse) | !mi(prtvtask) | !mi(prtvtatr) | !mi(prtvtabe) | !mi(prtvtbg) | !mi(prtvtach) | !mi(prtvtadk) | !mi(prtvtaee) | !mi(prtvtaes) | !mi(prtvtfi) | !mi(prtvtafr) | !mi(prtvtagb) | !mi(prtvtahu) | !mi(prtvtbnl) | !mi(prtvtapl) | !mi(prtvtro) | !mi(prtvtru) | !mi(prtvtbsi) | !mi(prtvtaua) | !mi(prtvtat) | !mi(prtvtch) | !mi(prtvtcz) | !mi(prtvtdk) | !mi(prtvtee) | !mi(prtvtfr) | !mi(prtvtagr) | !mi(prtvthu) | !mi(prtvtis) | !mi(prtvtait) | !mi(prtvtlu) | !mi(prtvtanl) | !mi(prtvtpl) | !mi(prtvtpt) | !mi(prtvtasi) | !mi(prtvtsk) | !mi(prtvttr) | !mi(prtvtua) | !mi(prtvtbe) | !mi(prtvtes) | !mi(prtvtgr) | !mi(prtvtil) | !mi(prtvtit) | !mi(prtvtnl) | !mi(prtvtsi)


gen green_proenv = .
label var green_proenv "Vote Green"



* Code Green party votes, noting that the voting variable names change between ESS rounds
replace green_proenv = inlist(prtvtcat, 5) | inlist(prtvtbat, 5) | inlist(prtvtaat, 5) if !(mi(prtvtcat) & mi(prtvtbat) & mi(prtvtaat))
replace green_proenv = inlist(prtvtdbe, 1, 7) | inlist(prtvtcbe, 1, 11 ) | inlist(prtvtbbe, 1, 10 ) | inlist(prtvtabe, 1, 10) if !(mi(prtvtdbe) & mi(prtvtcbe) & mi(prtvtbbe) & mi(prtvtcbe))
replace green_proenv = inlist(prtvtgch, 5) | inlist(prtvtfch, 5) | inlist(prtvtech, 5) | inlist(prtvtdch, 5) | inlist(prtvtcch, 8) | inlist(prtvtbch, 8) | inlist(prtvtach, 10) ///
			if !(mi(prtvtgch) &mi(prtvtfch) &mi(prtvtech) &mi(prtvtdch) &mi(prtvtcch) & mi(prtvtbch) & mi(prtvtach))
replace green_proenv = inlist(prtvtbcy, 6) | inlist(prtvtacy, 5) if !(mi(prtvtbcy) & mi(prtvtacy))
replace green_proenv = inlist(prtvtecz, 7) if !(mi(prtvtecz))
replace green_proenv = inlist(prtvede1, 4) | inlist(prtvede2, 4) | /// 
			inlist(prtvdde1, 3) | inlist(prtvdde2, 3) | ///
			inlist(prtvcde1, 3) | inlist(prtvcde2, 3) | ///
			inlist(prtvbde1, 3) | inlist(prtvbde2, 3) | ///
			inlist(prtvade1, 3) | inlist(prtvade2, 3) ///
			if !(mi(prtvede1) & mi(prtvede2) & mi(prtvdde1) & mi(prtvdde2) & mi(prtvcde1) & mi(prtvcde2) & mi(prtvbde1) & mi(prtvbde2) & mi(prtvade1) & mi(prtvade2))
replace green_proenv = inlist(prtvtddk, 4, 10) | inlist(prtvtcdk, 4) | inlist(prtvtbdk, 4) | inlist(prtvtadk, 5) if !(mi(prtvtddk) & mi(prtvtcdk) & mi(prtvtbdk) & mi(prtvtadk))
replace green_proenv = inlist(prtvtgee, 5) | inlist(prtvtfee, 5) | inlist(prtvteee, 5) | inlist(prtvtdee, 6) |inlist(prtvtcee, 6) | inlist(prtvtbee, 6) if !(mi(prtvtgee) & mi(prtvtfee) & mi(prtvteee) & mi(prtvtdee) & mi(prtvtcee) & mi(prtvtbee) )
replace green_proenv = inlist(prtvtees, 7) | inlist(prtvtdes, 7) | inlist(prtvtaes, 6) if !(mi(prtvtees) & mi(prtvtdes) & mi(prtvtaes))
replace green_proenv = inlist(prtvtdfi, 10) |inlist(prtvtcfi, 12) | inlist(prtvtbfi, 13) | inlist(prtvtafi, 7) if !(mi(prtvtdfi) & mi(prtvtcfi) & mi(prtvtbfi) & mi(prtvtafi))
replace green_proenv = inlist(prtvtdfr, 6) |inlist(prtvtcfr, 12) | inlist(prtvtbfr, 12) | inlist(prtvtafr, 14) if !( mi(prtvtdfr) & mi(prtvtcfr) & mi(prtvtbfr) & mi(prtvtafr))
replace green_proenv = inlist(prtvtcgb, 6, 15) | inlist(prtvtbgb, 6) | inlist(prtvtagb, 6) if !(mi(prtvtcgb) & mi(prtvtbgb) & mi(prtvtagb))
replace green_proenv = inlist(prtvtahr, 9) if !(mi(prtvtahr))
replace green_proenv = inlist(prtvtfhu, 6) | inlist(prtvtehu, 3) | inlist(prtvtdhu, 5) | inlist(prtvtchu, 13) if !( mi(prtvtfhu) & mi(prtvtehu) & mi(prtvtdhu) & mi(prtvtchu))
replace green_proenv = inlist(prtvtcie, 4) | inlist(prtvtbie, 4) | inlist(prtvtaie, 3) if !(mi(prtvtcie) & mi(prtvtbie) & mi(prtvtaie))
replace green_proenv = inlist(prtvtcis, 3) | inlist(prtvtbis, 10) | inlist(prtvtais, 4) if !(mi(prtvtcis) & mi(prtvtbis) & mi(prtvtais))
replace green_proenv = inlist(prtvblt1, 12) | inlist(prtvblt2, 13) | inlist(prtvblt3, 13) if !(mi(prtvblt1) & mi(prtvblt2) & mi(prtvblt3))
replace green_proenv = inlist(prtvtalv, 16) if !(mi(prtvtalv))
replace green_proenv = inlist(prtvtgnl, 8) | inlist(prtvtfnl, 8) | inlist(prtvtenl, 7) | inlist(prtvtdnl, 7) |inlist(prtvtcnl, 6) | inlist(prtvtbnl, 6) | inlist(prtvtanl, 6) ///
			if !(mi(prtvtgnl) & mi(prtvtfnl) & mi(prtvtenl) & mi(prtvtdnl) & mi(prtvtcnl) & mi(prtvtbnl) & mi(prtvtanl))
replace green_proenv = inlist(prtvtbno, 10)  if !(mi(prtvtbno))
replace green_proenv = inlist(prtvtcpt, 15)  if !(mi(prtvtcpt))
replace green_proenv = inlist(prtvtcse, 4) | inlist(prtvtbse, 4) | inlist(prtvtase, 4) if !(mi(prtvtcse) & mi(prtvtbse) & mi(prtvtase))

gen green_recoded = green_proenv /*vote green is a binary indicator so the pro-environment indicator is the same as the "continuous"*/

gen green_proenv_with0s = green_proenv
replace green_proenv_with0s = 0 if mi(green_proenv_with0s) & has_party==1
label var green_proenv_with0s "Vote Green Including Zeros"

*** Create indices**************************************************************

* Create an energy generation index rather than using all the enegry sources as independent outcomes
egen energy_recoded = rmean(elgcoal_recoded elghydr_recoded elgsun_recoded)
egen energy_proenv = rmean(elgcoal_proenv elghydr_proenv elgsun_proenv)
label var energy_recoded "Pro-clean energy beliefs"
label var energy_proenv "Pro-clean energy beliefs"




egen beliefs_proenv = rmean(/*elgcoal_proenv elgngas_proenv elghydr_proenv elgnuc_proenv*/ /*elgsun_proenv*/ /*elgwind_proenv elgbio_proenv*/ energy_proenv wrdpfos_proenv clmchng_proenv /*clmthgt_proenv*/ wrclmch_proenv ccgdbd_proenv)
egen behaviors_proenv = rmean(eneffap_proenv rdcenr_proenv clmthgt_proenv /*+ wrclmch_proenv*/)
egen policy_proenv = rmean(inctxff_proenv sbsrnen_proenv banhhap_proenv)
egen voting_proenv = rmean(/*lrscale_proenv*/ green_proenv /*liberal_proenv*/)


egen beliefs_recoded = rmean(/*elgcoal_recoded elgngas_recoded elghydr_recoded elgnuc_recoded*/ /*elgsun_recoded*/ /*elgwind_recoded elgbio_recoded*/ energy_recoded wrdpfos_recoded clmchng_recoded /*clmthgt_recoded*/ wrclmch_recoded ccgdbd_recoded)
egen behaviors_recoded = rmean(eneffap_recoded rdcenr_recoded clmthgt_recoded /*+ wrclmch_recoded*/)
egen policy_recoded = rmean(inctxff_recoded sbsrnen_recoded banhhap_recoded)
egen voting_recoded = rmean(/*lrscale_recoded*/ green_recoded /*liberal_recoded*/)

label var beliefs_proenv "Pro-environmental beliefs"
label var behaviors_proenv "Pro-environmental behaviors"
label var policy_proenv "Pro-environmental policy preferences"
label var voting_proenv "Pro-environmental voting"

label var beliefs_recoded "Pro-environmental beliefs"
label var behaviors_recoded "Pro-environmental behaviors"
label var policy_recoded "Pro-environmental policy preferences"
label var voting_recoded "Pro-environmental voting"


* Create standardized versions of each index
foreach var in "beliefs" "behaviors" "policy" "voting" {
	su `var'_proenv 
	gen `var'_proenv_sd = (`var'_proenv - r(mean) ) / r(sd) 
	local lab: variable label `var'_proenv
	label var `var'_proenv_sd "`lab' (standardized)"
}



********************************************************************************
********************************************************************************

**** cleanup data and construct necesssary variables

keep eduyrs essround minEdu implementedYear cntry in_sample  agea yrbrn gndr brncntr cntbrthd *_proenv* *_recoded has_party

encode cntry, gen(cntry_numeric)


winsor eduyrs, gen(eduyrs_wins) p(0.01)

gen yr = yrbrn-1950
gen yr2 = yr^2
gen yr3 = yr^3
label var yr "Birth year relative to 1950"
label var yr2 "Birth year relative to 1950 squared"
label var yr3 "Birth year relative to 1950 cubed"

egen cohortBin10 = cut(yrbrn), at(1910(10)2020)
egen cohortBin5 = cut(yrbrn), at(1910(5)2020)
label var cohortBin10 "10 year cohort bin"
label var cohortBin5 "5 year cohort bin"

gen cntryXlaw = cntry + string(minEdu) if !mi(minEdu)
encode cntryXlaw, gen(cntryXlaw_numeric)
label var cntryXlaw_numeric "Country by Law"

save "Cleaned_ESS.dta", replace





